﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Account.BLL;
using Yipusoft.Account.Model;
using Yipusoft.Common.BLL;
using Yipusoft.Common.Model;
using Yipusoft.Task.BLL;
using Yipusoft.Task.Model;
using Yipusoft.Evaluate.BLL;
using Yipusoft.Evaluate.Model;
using System.Data;


public partial class CheckDepartment : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGrid();
        }
    }
    private string GetDepartmentName2(string departmentID)
    {
        if (string.IsNullOrEmpty(departmentID))
            return "";

        if (departmentID.Length == 7)
            return Yipusoft.Account.BLL.Department.GetDepartment(departmentID).FullName;

        if (departmentID.Length == 5)
            return Yipusoft.Account.BLL.Department.GetDepartment(departmentID.Substring(0, 4) + "000").FullName;

        if (departmentID.Length == 4)
            return Yipusoft.Account.BLL.Department.GetDepartment(departmentID.Substring(0, 4) + "000").FullName;

        if (departmentID.Length == 6)
            return Yipusoft.Account.BLL.Department.GetDepartment(departmentID + "0").FullName;

        return "";

    }
    public string GetWhere(string DepartmentID2)
    {

        string DepartmentID = DepartmentID2;
        string ReturnStr = string.Empty;

        List<RoleInfo> list = Yipusoft.Account.BLL.User.GetRoleList(Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).UserID);

        bool Flag = list.Where(o => o.RoleID.Equals("100110")).Count() > 0;
        if (Flag)
        {
            ReturnStr = " Left(DepartmentID2,4)='" + DepartmentID.Substring(0, 4) + "'";
        }
        else
        {
            ReturnStr = "Left(DepartmentID2,6)='" + DepartmentID.Substring(0, 6) + "'";

        }
        return ReturnStr;
    }
    private void BindGrid()
    {
        if (Request["SM"] != null)
        {
            divPromt.Visible = true;
            StandardInfo standard = Standard.GetStandard();
            decimal TotalScore = standard.CheckPer;
            lblPerent.Text = Convert.ToString(TotalScore * 100);
            lblTotle.Text = standard.TotalScore.ToString("0");
            lblGS.Text = Request["GS"];
        }
        string year = Request["year"];

        string department = GetDepartmentName2(Request.QueryString["DepartmentID"]);
        UserGrid.Caption = "<span>" + year + "年考核验收扣分情况统计表（" + department + "）</span>";
        string where = GetWhere(Request["DepartmentID"]) + " and CheckID in (select CheckID from Checks where year(CheckDate)=" + year + " and month(CheckDate)>=" + Request["SM"] + " and month(CheckDate)<=" + Request["EM"] + " )  order by CheckID ";
        List<CheckItemInfo> items = CheckItem.GetList(where);
        UserGrid.DataSource = items;
        UserGrid.DataBind();
    }
    protected void UserGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = (e.Row.RowIndex + 1).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
            Label CheckName = e.Row.FindControl("CheckName") as Label;
            CheckItemInfo info = e.Row.DataItem as CheckItemInfo;
            CheckName.Text = CheckItem.GetCheckItem(info.CheckID).ItemName;
        }
    }
    public string GetDepartmentName(string departmentID)
    {
        return Department.GetDepartment(departmentID).FullName;
    }
}
